package com.rainwood.water_authority.util;
import android.content.Context;
import android.content.SharedPreferences;
import com.rainwood.water_authority.base.App;

public class SharePrenceHelper {

	private static final String P_NAME = "PDA";

	private static SharedPreferences sp;
	private static SharePrenceHelper ph;

	private SharePrenceHelper() {}

	public static void deleteData(String name) {
		if (ph == null || sp == null) {
			ph = new SharePrenceHelper();
			sp = App.app.getSharedPreferences(P_NAME, 0);
		}
		SharedPreferences.Editor editor = sp.edit();
		editor.remove(name);
		editor.commit();
	}

	public static SharePrenceHelper getPerferences(Context a) {
		if (ph == null || sp == null) {
			ph = new SharePrenceHelper();
			sp = App.app.getSharedPreferences(P_NAME, 0);
		}
		return ph;
	}

	public static SharePrenceHelper getPerferences() {
		return ph;
	}

	public static void setInfo(String name, String data) {
		if (ph == null || sp == null) {
			ph = new SharePrenceHelper();
			sp = App.app.getSharedPreferences(P_NAME, 0);
		}
		SharedPreferences.Editor e = sp.edit().putString(name, data);
		e.commit();
	}

	public static void setInfo(String name, int data) {
		if (ph == null || sp == null) {
			ph = new SharePrenceHelper();
			sp =App.app.getSharedPreferences(P_NAME, 0);
		}
		SharedPreferences.Editor e = sp.edit().putInt(name, data);
		e.commit();
	}

	public static void setInfo(String name, boolean data) {
		if (ph == null || sp == null) {
			ph = new SharePrenceHelper();
			sp = App.app.getSharedPreferences(P_NAME, 0);
		}
		SharedPreferences.Editor e = sp.edit().putBoolean(name, data);
		e.commit();
	}

	public static int getIntData(String name) {
		if (ph == null || sp == null) {
			ph = new SharePrenceHelper();
			sp = App.app.getSharedPreferences(P_NAME, 0);
		}
		return sp.getInt(name, 0);
	}

	public static String getStringData(String name) {
		if (ph == null || sp == null) {
			ph = new SharePrenceHelper();
			sp = App.app.getSharedPreferences(P_NAME, 0);
		}
		return sp.getString(name, "");
	}

	public static boolean getBooleanData(String name) {
		if (ph == null || sp == null) {
			ph = new SharePrenceHelper();
			sp = App.app.getSharedPreferences(P_NAME, 0);
		}
		return sp.getBoolean(name, false);
	}

	public static void setInfo(String name, long data) {
		if (ph == null || sp == null) {
			ph = new SharePrenceHelper();
			sp =App.app.getSharedPreferences(P_NAME, 0);
		}
		SharedPreferences.Editor e = sp.edit().putLong(name, data);
		e.commit();
	}

	public static long getLongData(String name) {
		if (ph == null || sp == null) {
			ph = new SharePrenceHelper();
			sp =App.app.getSharedPreferences(P_NAME, 0);
		}
		return sp.getLong(name, 0);
	}

}
